package com.zmt.mrms.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.zmt.mrms.entity.MedicalRecord;
import com.zmt.mrms.entity.MedicineList;
import com.zmt.mrms.entity.PaymentRecord;
import com.zmt.mrms.entity.PrescriptionRecord;
import com.zmt.mrms.entity.UserDoctor;

@Mapper
public interface DoctorMapper {

	@Update("update medical_record set finish_time=#{finishTime} where id=#{medicalRecordId}")
	int finishMedical(@Param("medicalRecordId") int medicalRecordId, @Param("finishTime") String finishTime);

	@Update("update prescription_record set finish_time=#{finishTime} where medical_record_id=#{medicalRecordId}")
	int finishPrescription(@Param("medicalRecordId") int medicalRecordId, @Param("finishTime") String finishTime);

	@Select("select * from prescription_record where ISNULL(finish_time) AND apothecary_id<>''")
	List<PrescriptionRecord> prepareForGetMedicine();

	@Update("update payment_record set medicine_cost=#{price},medicine_status=false where medical_record_id=#{medicalRecordId}")
	int setPaymentMedinicePrice(@Param("price") Double price, @Param("medicalRecordId") int medicalRecordId);

	@Select("select * from medicine_list where name=#{name}")
	MedicineList getMedicineInfo(@Param("name") String name);

	@Select("select * from prescription_record where medical_record_id=#{medicalRecordId}")
	PrescriptionRecord getPreRecord(@Param("medicalRecordId") int medicalRecordId);

	@Update("update prescription_record set apothecary_id=#{apothecaryId},double_check=#{doubleCheck} where medical_record_id=#{medicalRecordId}")
	int doubleCheck(PrescriptionRecord prescriptionRecord);

	@Select("select * from prescription_record where ISNULL(apothecary_id)")
	List<PrescriptionRecord> getPrescriptionRecord();

	@Insert("insert into prescription_record(medical_record_id,doctor_id,diagnosis,advices,prescription,create_time) values(#{medicalRecordId},#{doctorId},#{diagnosis},#{advices},#{prescription},#{createTime})")
	int setPrescription(PrescriptionRecord prescriptionRecord);

	@Select("select * from medical_record where id=#{id}")
	MedicalRecord getMedicalRecord(@Param("id") int id);

	@Select("select * from payment_record where medical_record_id=#{id}")
	PaymentRecord isPaid(@Param("id") int id);

	@Select("select * from medicine_list")
	List<MedicineList> getMedicineList();

	/**
	 * 登录模块、个人信息模块
	 */

	@Update("update user_doctor set account=#{account},password=#{password},email=#{email},phone=#{phone},address=#{address} where id=#{id}")
	int updateDoctorInfo(UserDoctor userDoctor);

	@Select("select * from user_doctor where id=#{id}")
	UserDoctor findDoctorbyId(@Param("id") int id);

	@Select("select * from user_doctor where account=#{account} and password=#{pwd}")
	UserDoctor findDoctor(@Param("account") String account, @Param("pwd") String pwd);

}
